home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 830 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. From: clamage@Eng.Sun.COM (Steve Clamage)
  2. Message-ID: <4ivdsv$p3p@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 22 Mar 1996 23:42:23 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 23 Mar 96 08:13:55 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Referencing pointers after delete
  9. Organization: Sun Microsystems Inc.
  10. References: <4iushh$q3@galaxy.ucr.edu>
  11. Reply-To: clamage@Eng.Sun.COM
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMVOyzOEDnX0m9pzZAQG3awF/Wfqnp+HmRx6Zi8lTAJGDkr5UgTcgG0Dn
  14.     g2ZIZPfp0wAig8WqEUAJ4jTNbDOSGSPU
  15.     =sURP
  16.  
  17. In article q3@galaxy.ucr.edu, thp@cs.ucr.edu (Tom Payne) writes:
  18. >Steve Clamage (clamage@Eng.Sun.COM) wrote:
  19. >
  20. >: Even if the value of a pointer after its referent was deleted were 
  21. >: required to be valid, it is still not possible to write a portable pointer
  22. >: validity checker for C or C++. Example, assuming that it is always safe
  23. >: to read the value of any pointer:
  24. >: 
  25. >:     void foo(int* p) {
  26. >:         // is p valid?
  27. >:     }
  28. >: How are you going to determine portably whether p is valid in foo? 
  29. >
  30. >By passing it to a checking routine, of course. ;-)  Given the curent
  31. >standard, a call to such a routine can elicit undefined behavior in an
  32. >otherwise portable program:
  33. >
  34. >   void bar(int*& p) {
  35. >      checkOut(p);  // p is passed by value to checkOut.
  36. >      p = 0;
  37. >   } 
  38. >
  39. >I don't mean to imply that one can portably detect *all* invalid
  40. >pointers, but with help from the compiler software-based solutions
  41. >can give coverage that is as complete as those based on hardware.
  42. >In either case, it is not particularly helpful that the behavior
  43. >becomes undefined the moment an invalid value is detected.
  44.  
  45. "Undefined" doesn't mean "halt and catch fire". (Don't you find annoying
  46. the Star Trek convention, from Classic through Voyager, that any trouble
  47. on board results in the computers bursting into flame?) "Undefined" means
  48. portable programs are given no assurances about behavior.
  49.  
  50. An implementation can provide all the checking it wants, and can provide
  51. hooks to allow others to do the checking. Documentation may provide clever
  52. third parties the information they need to make add-on checkers. Some
  53. ISV's are making quite a nice living doing exactly that.
  54.  
  55. Pointer validation isn't going to be portable, as I pointed out before.
  56. I don't see any advantage in trying to restrict the kind or form of checking
  57. that systems are allowed to implement. I would applaud a hardware-based
  58. mechanism, and I would resent a programming language standard that made
  59. it non-conforming.
  60.  
  61. ---
  62. Steve Clamage, stephen.clamage@eng.sun.com
  63. ---
  64. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  65. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  66. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  67. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  68. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  69.